package ${basePackage}.generator.file;

import cn.hutool.core.io.FileUtil;
import cn.hutool.core.io.IORuntimeException;
import cn.hutool.core.util.ArrayUtil;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;

/**
 * @author ${author}
 * @verison ${version}
 */
public class StaticGenerator {




    public static void copyFilesByHutool(String inputPath, String outputPath, boolean isOverride) {
        FileUtil.copy(inputPath, outputPath, isOverride);

    }

    public static void copyFileByRecursive(File inputFile, File outputFile) throws IOException {


        if (inputFile.isDirectory()) {
            File destOutputFile = new File(outputFile, inputFile.getName() + "-test");

            if (!destOutputFile.exists()) {
                destOutputFile.mkdir();
            }

            File[] files = inputFile.listFiles();

            if (ArrayUtil.isEmpty(files)) {
                return;
            }


            for (File file : files) {
                copyFileByRecursive(file, destOutputFile);
            }


        } else {
            Path p = outputFile.toPath().resolve(inputFile.getName());
            Files.copy(inputFile.toPath(), p, StandardCopyOption.REPLACE_EXISTING);
        }


    }


    public void mineCopy(File inputFile, File outputFile) throws IOException {

        //
        if (inputFile.isDirectory()) {
            //
            File destOutputFile = new File(outputFile, inputFile.getName() + "mineCopy");

            if (!destOutputFile.exists()) {
                destOutputFile.mkdir();
            } else {
                return;
            }


            File[] files = inputFile.listFiles();
            for (File file : files) {
                mineCopy(file, destOutputFile);
            }
        } else {
            Files.copy(inputFile.toPath(), outputFile.toPath().resolve(inputFile.getName() + "mineCopy"), StandardCopyOption.REPLACE_EXISTING);
        }
    }

}
